<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // https://leetcode-cn.com/problems/add-strings/
        // 用 charAt 从最后开始慢慢判断，考虑进位的问题
        // 第一次做没做出来
        var addStrings = function(num1, num2) {
            let sum = [];
            let add = 0; // 进位
            let i = num1.length - 1;
            let j = num2.length - 1;
            while (i >= 0 || j >= 0 || add !== 0) {
                let x = +num1.charAt(i)
                let y = +num2.charAt(j)
                let count = x + y + add;
                sum.push(count % 10);
                add = Math.floor(count / 10); 
                i--;
                j--;
            }
            return sum.reverse().join('');
        };

        console.log(addStrings('11', '123'));
    </script>
</body>
</html>